package uk.ac.durham.tel.synergynet.covanto.workspace.ui.view;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.part.ViewPart;

import uk.ac.durham.tel.synergynet.covanto.project.ui.navigation.WorkspaceProjectsContentProvider;
import uk.ac.durham.tel.synergynet.covanto.project.ui.navigation.WorkspaceProjectsLabelProvider;
import uk.ac.durham.tel.synergynet.covanto.workspace.ui.model.WorkspaceNode;

public class StudyWorkspaceExplorerViewPart extends ViewPart {
	
	public static final String ID = "uk.ac.durham.tel.synergynet.covanto.workspace.ui.view.StudyWorkspaceExplorerViewPart";
	
	private TreeViewer projectsTreeViewer;
	
	@Override
	public void dispose() {
		super.dispose();
	}

	public void createPartControl(Composite parent) {
		projectsTreeViewer = new TreeViewer(parent, SWT.NONE);
		setupProjectsTreeViewerContent();
		setupMenuContribution();
		setupSelectionProvider();
	}

	private void setupSelectionProvider() {
		getSite().setSelectionProvider(projectsTreeViewer);
	}

	private void setupMenuContribution() {
		MenuManager menuManager = new MenuManager();
		Menu menu = menuManager.createContextMenu (projectsTreeViewer.getControl());
		projectsTreeViewer.getControl().setMenu(menu);
		getSite().registerContextMenu(menuManager, projectsTreeViewer);
	}

	private void setupProjectsTreeViewerContent() {
		WorkspaceProjectsContentProvider workspaceProjectsContentProvider = new WorkspaceProjectsContentProvider(); 
		projectsTreeViewer.setContentProvider(workspaceProjectsContentProvider);
		projectsTreeViewer.setLabelProvider(new WorkspaceProjectsLabelProvider(workspaceProjectsContentProvider.getKnownElements()));
		projectsTreeViewer.setInput(new WorkspaceNode(null));
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}

}
